<template>
	<view>
		<view class="content">
			<view class="acDiv">
				<text class="proName">项目名称</text>
				<text class="ProCont">{{ pro_id }}</text>
			</view>
			<view class="acDiv">
				<text class="proName">机构名称</text>
				<text class="ProCont">{{ org_id }}</text>
			</view>
			<view class="acDiv">
				<text class="proName">活动名称</text>
				<input type="text" class="ProCont" v-model="active_name" />
				<!-- <text class="ProCont">{{}}</text> -->
			</view>
			<view class="acDiv">
				<text class="proName">活动地点</text>
				<input type="text" class="ProCont" v-model="place" />
				<!-- <text class="ProCont">{{place}}</text> -->
			</view>
			<view class="acDiv">
				<text class="proName">活动内容</text>
				<input type="text" class="ProCont" v-model="detail" />
				<!-- <text class="ProCont pContent">{{detail}}</text> -->
			</view>
			<view class="acDiv">
				<text class="proName">预计参加人数</text>
				<input type="number" class="ProCont" v-model="count" />
				<!-- <text class="ProCont">{{count}}人</text> -->
			</view>
			<view class="acDiv">
				<text class="proName">项目联系人</text>
				<input type="text" class="ProCont" v-model="contacts" />
				<!-- <text class="ProCont">{{contacts}}</text> -->
			</view>
			<view class="acDiv">
				<text class="proName">联系方式</text>
				<input type="text" class="ProCont" v-model="phone" />
				<!-- <text class="ProCont">{{phone}}</text> -->
			</view>
			<view class="acDiv">
				<text class="proName proTime">时间</text>
				<view class="ProCont">
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" class="uni-input">
						<view>{{ date }}</view>
					</picker>
				</view>
			</view>
			<view class="acDiv supervise">
				<view class="proName">检测方</view>
				<view>
					<!-- <checkbox-group name="" @change="typeChange">
						<label class="radio">
							<radio value="1" class="jiance" />
							<image src="../../../static/jia.png" mode="" class="jia"></image>
							<text>满意度方</text>
						</label>
						<label class="radio">
							<radio value="1" class="jiance" />
							<image src="../../../static/jia.png" mode="" class="jia"></image>
							<text>评估机构</text>
						</label>
					</checkbox-group> -->
					<checkbox-group @change="checkboxChange">
						<label v-for="item in items" :key="item.value" class="radio">
							<view><checkbox :value="item.value" :checked="item.checked" /></view>
							<view>{{ item.name }}</view>
						</label>
					</checkbox-group>
				</view>
			</view>
		</view>
		<button type="primary" class="apply" @click="postSpro()">提交</button>
	</view>
</template>

<script>
export default {
	data() {
		const currentDate = this.getDate({
			format: true
		});
		return {
			date: currentDate,
			pro_id: '',
			org_id: '',
			id: '',
			active_name: '',
			place: '',
			detail: '',
			count: '',
			contacts: '',
			phone: '',
			radio: '1',
			end_time:'2018',
			items: [{
			                        value: '1',
			                        name: '满意度方',
									//checked: 'false'
			                    },
			                    {
			                        value: '2',
			                        name: '评估机构',
			                       // checked: 'false'
			                    },],

			// end_time:_this.end_time,
		};
	},
	computed: {
		startDate() {
			return this.getDate('start');
		},
		endDate() {
			return this.getDate('end');
		}
	},
	onLoad(res) {
		console.log(res);
		this.pro_id = res.name;
		this.org_id = res.company;
		this.id = res.id;
	},
	onShow(res) {
		this.getExecute();
	},
	methods: {
		checkboxChange(e) {
			var items = this.items,
				values = e.detail.value;
			this.radio = values
			console.log(this.radio);
			for (var i = 0, lenI = items.length; i < lenI; ++i) {
				const item = items[i];
				if (values.includes(item.value)) {
					this.$set(item, 'checked', true);
				} else {
					this.$set(item, 'checked', false);
				}
			}
		},
		getExecute() {
			this.$get('v1/pro/execute', { org_id: uni.getStorageSync('id') }).then(res => {
				this.data = res.data.data;
			});
		},
		postSpro() {
			var _this = this;
			let id = this.id;
			// if(this.pro_id&&this.org_id&&this.active_name&&this.place&&this.detail&&this.count&&this.contacts&&this.phone&&this.end_time==''){
			// 	uni.showToast({
			// 		title:'信息不能为空！'
			// 	})
			// 	return;
			// }else{
			// 	alert(111)
			// }
			this.$post('v1/actives/activepro', {
				type: _this.radio,
				pro_id: _this.id,
				org_id: uni.getStorageSync('id'),
				active_name: _this.active_name,
				place: _this.place,
				detail: _this.detail,
				count: _this.count,
				contacts: _this.contacts,
				phone: _this.phone,
				end_time: _this.end_time
			}).then(res => {
				console.log('aaa' + res);
				uni.navigateTo({
					// url:'../pmActivityMonitoring/pmActivityMonitoring?id='+_this.id+'&three=1'
					url: '../pmActivityMonitoring/pmActivityMonitoring?id=' + _this.id
				});
			});
		},

		// bindPickerChange: function(e) {
		// 	console.log('picker发送选择改变，携带值为', e.target.value)
		// 	this.index = e.target.value
		// },
		bindDateChange: function(e) {
			this.date = e.target.value;
		},
		// bindTimeChange: function(e) {
		// 	this.time = e.target.value
		// },
		getDate(type) {
			const date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();

			if (type === 'start') {
				year = year - 60;
			} else if (type === 'end') {
				year = year + 2;
			}
			month = month > 9 ? month : '0' + month;
			day = day > 9 ? day : '0' + day;
			return `${year}-${month}-${day}`;
		}
	}
};
</script>

<style>
.apply {
	background-color: #c30d24;
	width: 620rpx;
	line-height: 78rpx;
	border-radius: 40rpx;
	font-size: 28rpx;
	margin-top: 40rpx;
}
.acDiv {
	border-bottom: 3rpx solid #eaeaea;
	padding: 20rpx 0;
	margin: 0 20rpx;
	overflow: hidden;
	font-weight: 400;
}
.proName {
	font-size: 28rpx;
}
.ProCont {
	font-size: 26rpx;
	float: right;
	width: 415rpx;
	text-align: right;
	line-height: 40rpx;
}
.pContent {
	text-align: left;
}

.proTime {
	padding-top: 10rpx;
}
.uni-input {
	padding: 0;
}
.radio {
	margin: 0 44rpx;
}
.jia {
	width: 26rpx;
	height: 30rpx;
	vertical-align: middle;
	margin: 20rpx 10rpx;
}
.supervise {
	border: 0;
}
</style>
